From 7c049f32a4d479cfe67bc54a41a9b0f416eab9cd Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Sat, 28 Jun 2014 16:18:02 -0700 Subject: [PATCH] Add a hack to make github urls case-insensitive. Fixes #84 --- src/cargo/sources/git/source.rs | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/src/cargo/sources/git/source.rs b/src/cargo/sources/git/source.rs index 2ecd0bcf1..9b45762ad 100644 --- a/src/cargo/sources/git/source.rs +++ b/src/cargo/sources/git/source.rs @@ -68,11 +68,8 @@ fn ident(location: &Location) -> String { str::from_utf8(last).unwrap().to_str() } Remote(ref url) => { - // Remove the trailing '/' so that 'split' doesn't give us - // an empty string, making '../foo/' and '../foo' both - // result in the name 'foo' (#84) let path = strip_trailing_slash(url.path.as_slice()); - path.split('/').last().unwrap().to_str() + path.as_slice().split('/').last().unwrap().to_str() } }; @@ -82,10 +79,15 @@ fn ident(location: &Location) -> String { ident }; - format!("{}-{}", ident, to_hex(hasher.hash(&location.to_str()))) + let location = canonicalize_url(location.to_str().as_slice()); + + format!("{}-{}", ident, to_hex(hasher.hash(&location.as_slice()))) } fn strip_trailing_slash<'a>(path: &'a str) -> &'a str { + // Remove the trailing '/' so that 'split' doesn't give us + // an empty string, making '../foo/' and '../foo' both + // result in the name 'foo' (#84) if path.as_bytes().last() != Some(&('/' as u8)) { path.clone() } else { @@ -93,6 +95,20 @@ fn strip_trailing_slash<'a>(path: &'a str) -> &'a str { } } +fn canonicalize_url(url: &str) -> String { + // HACKHACK: For github URL's specifically just lowercase + // everything. GitHub traits both the same, but they hash + // differently, and we're gonna be hashing them. This wants a more + // general solution, and also we're almost certainly not using the + // same case conversion rules that GitHub does. (#84) + let lower_url = url.chars().map(|c|c.to_lowercase()).collect::(); + if lower_url.as_slice().contains("github.com") { + lower_url + } else { + url.to_string() + } +} + impl<'a, 'b> Show for GitSource<'a, 'b> { fn fmt(&self, f: &mut Formatter) -> fmt::Result { try!(write!(f, "git repo at {}", self.remote.get_location())); -- 2.30.2